package com.systop.supervise.service.Impl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.systop.common.pojo.Teacher;
import com.systop.supervise.mapper.TeacherMapper;
import com.systop.supervise.service.TeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public  class TeacherServiceImpl implements TeacherService {

    @Autowired
    private TeacherMapper teacherMapper;

    @Override
    public Teacher SudentLogin(Teacher teacher) {
        return teacherMapper.TeacherLogin(teacher);
    }

    @Override
    public List<Teacher> teacherSupList() {
        //上页 下页  和 想要跳到的 页码在页面获取当前的页码值 上页就是减一 下页就是加以  传值当前的页码
        int page =1;//起始页码默认为1
        int pageSize=10;//每页的数据条数默认为五条
        PageHelper.startPage(page,pageSize);//分页起始码以及每页的数据条数
        PageInfo pageInfo=new PageInfo(teacherMapper.teacherSupList());//把从数据库查到的数据给到pageInfo
 	 //尾页  
      if (page> pageInfo.getPages()){
	//总共个的页面
           page=pageInfo.getPages();//尾页
        PageHelper.startPage(page,pageSize);//分页起始码以及每页的数据条数
        PageInfo pageInfo1=new PageInfo(teacherMapper.teacherSupList());//把从数据库查到的数据给到pageInfo
         return pageInfo1.getList();
        }
	//首页的上一页
         if (page==0){
           page=1;//首页的上一页bug解决 
            PageHelper.startPage(page,pageSize);//分页起始码以及每页的数据条数
           PageInfo pageInfo2=new PageInfo(teacherMapper.teacherSupList());//把从数据库查到的数据给到pageInfo
          return pageInfo2.getList();
        }
        return pageInfo.getList();
    }

    @Override
    public int insertSupervice(Teacher teacher) {
        return teacherMapper.insertSupervice(teacher);
    }

    @Override
    public int updataSupervice(Teacher teacher) {
        return teacherMapper.updataSupervice(teacher);
    }

    @Override
    public List<Teacher> teacherSupteacher(String tno) {
        return teacherMapper.teacherSupteacher(tno);
    }

    @Override
    public int deleteTeacher(String tno) {
        return teacherMapper.deleteTeacher(tno);
    }
}
